package ${packageName}.${moduleName}.service${subModuleName}.impl;

import org.ko.core.dao.support.Finder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import ${packageName}.${moduleName}.dao.${ClassName}Dao;
import ${packageName}.${moduleName}.domain${subModuleName}.${ClassName};
import ${packageName}.${moduleName}.controller.model${subModuleName}.${ClassName}Model;
import ${packageName}.${moduleName}.service${subModuleName}.${ClassName}Service;

/**
 * ${functionName}Service接口实现
 * @author ${classAuthor}
 * @version ${classVersion}
 */
@Service
@Transactional
public class ${ClassName}ServiceImpl implements ${ClassName}Service {

	@Autowired
	private ${ClassName}Dao dao;

	@Override
	public ${ClassName} addDo(${ClassName} bean) {
		dao.save(bean);

		return bean;
	}
	
	public void create(${ClassName}Model model)throws Exception{
		${ClassName} entity = (model.getBean());
		if(entity != null){
			if(entity.getId() != null && entity.getId() >0){
				dao.merge(entity);
			}else{
				dao.save(entity);
			}
		}
	}
	/**
	 * 删除实体
	 * @param model
	 * @throws Exception
	 */
	public void delete(${ClassName}Model model)throws Exception{
		dao.delete(model.getId());
	}
	
	/**
	 * 刷新实体
	 * @param model
	 * @throws Exception
	 */
	public void refresh(${ClassName}Model model)throws Exception{
		
	}
	
	/**
	 * 浏览详情
	 * @param model
	 * @throws Exception
	 */
	public void view(${ClassName}Model model)throws Exception{
		${ClassName} entity = dao.get(model.getId());
		Assert.notNull(entity, "你查看的对象不存在");
		
		model.setBean(entity);
	}
	
	/**
	 * 分页浏览
	 * @param model
	 * @throws Exception
	 */
	public void list(${ClassName}Model model)throws Exception{
		StringBuilder sb = new StringBuilder("FROM ${ClassName} where 1=1");
		Finder f = Finder.create(sb.toString());
		f.append(" order by id desc");
		
		dao.find(f, model);
	}
	
	/**
	 * 判断实体是否存在
	 * @param model
	 * @return
	 * @throws Exception
	 */
	public boolean isExist(${ClassName}Model model)throws Exception{
		return false;
	}
}